<?php require('includes/functions.php'); ?>
<!DOCTYPE html>
<html>
	<head>
		<title>LIST</title>
		<link href="css/style.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<?php 
			$filter = isset($_GET['filter']) ? $_GET['filter']:0;
			$employees = getAllEmployees($filter);
			$employees_temp = getAllEmployees();
		?>
        <div class="pambalot">
        <div class="left-pane">
            <div class="horizontal-table-div">
    		<?php if ($employees): ?>
    		<form action="index.php" method="GET">
    			<center>
    				<label for="filter">Employees</label>
    				<select name="filter" id="filter">
    					<option <?php if (!$filter) echo 'selected="selected"' ?> value="0">All</option>
    					<option <?php if ($filter == 1) echo 'selected="selected"' ?> value="1">Active Only</option>
    					<option <?php if ($filter == 2) echo 'selected="selected"' ?> value="2">Inactive Only</option>
    				</select>
    				<input type="submit" value="Filter" />
    			</center>
    		</form>
    		<table cellspacing="0" cellpadding="2" border="1" class="horizontal-table">
    			<tr>
    				<td colspan="6">
    					Found <?php echo count($employees) ?> out of <?php echo count($employees_temp) ?> employees. 
    				</td>
    			</tr>
    			<tr>
    				<th>Employee ID</th>
    				<th>Name</th>
    				<!--<th>Address</th>
    				<th>Contact</th>
    				<th>Email</th>
    				<th>Gender</th>
    				<th>Birthdate</th>-->
    				<th>Department</th>
    				<th>Job</th>
    				<th>Status</th>
    				<th>Actions</th>
    			</tr>
    			<?php foreach ($employees as $employee): ?>
    			<tr <?php echo ($employee->status_id != 1) ? 'class="inactive" title="This account is inactive"':null ?>>
    				<td>
    					<a href="view_employee.php?id=<?php echo $employee->employee_id ?>">
    						<?php echo $employee->employee_id ?>
    					</a>
    				</td>
    				<td><?php echo $employee->name ?></td>
    				<!--<td><?php echo $employee->address ?></td>
    				<td><?php echo $employee->contact ?></td>
    				<td><?php echo $employee->email ?></td>
    				<td><?php echo $employee->gender ?></td>
    				<td><?php echo date("M d, Y", strtotime($employee->birthdate)) ?></td>-->
    				<td><?php echo $employee->department ?></td>
    				<td><?php echo $employee->job ?></td>
    				<td><?php echo $employee->status ?></td>
    				<td>
    					<a href="edit_employee.php?id=<?php echo $employee->employee_id ?>"
    					<?php echo ($employee->status_id != 1) ? 'onclick="return confirm(\'This employee is currently inactive are you sure you want to modify this?\')"':null ?>>
    						Modify
    					</a>
    				</td>
    			</tr>
    			<?php endforeach ?>
    		</table>
    		<?php else: ?>
    			No employees found.
                <a href="index.php">Go back</a>
    		<?php endif ?>
            </div>
        </div>
        <div class="right-pane">
            <p><input type="button" value="Add Employee" onclick="location.href='add_employee.php'" /></p>
   			<p><input type="button" value="View Logs" onclick="location.href='view_logs.php'" /></p>
        </div>
        <div class="clear"></div>
        </div>
	</body>
</html>